using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 单例模式
/// </summary>
/// <typeparam name="T"></typeparam>
public class SingletonClass<T> where T :  ISingleton, new()
{

    private static T instance;
    private static bool initOk;
    public static T Instance
    {
        get
        {
            if (instance == null && !initOk)
            {
                instance = new T();
                initOk = true;
                //是否有方法可以在实例化时进行初始化
                Instance.Init();
            }
            return instance;
        }
        private set => instance = value;
    }
}
/// <summary>
/// 初始化
/// </summary>
public interface ISingleton
{
    void Init();
}